/**
 * Created by Administrator on 15-9-28.
 */
var interid=0;
var sec=119;
function djs(){
    $(".djs").text("重发("+sec+"s)");
    sec-=1;
    if(sec==-1){
        clearInterval(interid);
        sec=119;
        $(".djs").addClass("yzm");
        $(".djs").text("获取验证码");
        $(".djs").removeClass("djs");
    }
}
window.onload=function(){
var url=getUrl();
    $(".login-get-verify").on("click",function(){
        if(!$(this).hasClass("yzm"))
            return;
        var phonenum=$("#phonenum").val();
        if(phonenum=="")
        {
            showToast("手机号不能为空");
            return false;
        }
        if(phonenum.length!=11)
        {
            showToast("手机号格式不正确")
            return;
        }

        $.jsonp({
            url: 'http://'+url+'/api/user/sendsms_for_regist',
            data: {telphone:phonenum},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
               if(data.succ == false){
                  showToast(data.msg);
                  return;
               }else{
                  $(".yzm").text("重发(120s)");
                  $(".yzm").addClass("djs");
                  $(".yzm").removeClass("yzm");
               }
            },
            error: function (xOptions,textStatus) {
            }
        });

//        $(".login-get-verify").text("重发(120s)");
//        $(".login-get-verify").addClass("djs");
//        $(".login-get-verify").removeClass("login-get-verify");

        interid=setInterval(djs,1000);

    });

    $(".log-ljzc").on("click",function(){
        var phonenum=$("#phonenum").val();
        var yanzheng=$("#yanzheng").val();
        var password=$("#password").val();
        var passwordsure=$("#passwordsure").val();

        if(yanzheng == ""){
            showToast('请输入验证码~');
            return;
        }

        if(password == "")
        {
            showToast('请输入密码~');
            return;
        }
        if(password!=passwordsure)
        {
            showToast('两次输入的密码不一致');
            return;
        }
        $.jsonp({
            url: 'http://'+url+'/api/user/regist',
            data: {telphone:phonenum,code:yanzheng,password:password},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {

                if(data.succ==true){
                    showToast("注册成功～");
                    location.href="denglu.html";
                }else{
                    showToast(data.msg);
                }

            },
            error: function (xOptions,textStatus) {
                showToast("注册失败～");
            }
        });

    });



}

var  index = 1;
function onBackKeyDown() {

    if(index > 1){
    window.location = "denglu.html";
    }else{
    index++;
    }

}
